package com.weixiaodong.javabasic.Java中List使用细节;

import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListDemo2 {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> cwList = new CopyOnWriteArrayList<>();
        cwList.add("a");
        cwList.add("b");
        cwList.add("c");
        cwList.add("d");
        cwList.add("e");
        Iterator<String> iterator = cwList.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            if (next == "c") {
                cwList.remove(next); // 没有报出任何异常
                continue;
            }
            System.out.println(next);
        }
        System.out.println(cwList.size()); // 4
    }
}
